package com.kjlink.internal.workreport.report.model;


import cn.xuqiudong.common.base.model.BaseEntity;
import cn.xuqiudong.common.util.poi.export.ExcelField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.kjlink.internal.workreport.base.annotation.NoneColumn;
import com.kjlink.internal.workreport.helper.ReportCommonHelper;
import com.kjlink.internal.workreport.helper.SessionHelper;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.time.LocalDate;


/**
 * 实体类
 *
 * @author Vic.xu
 */
public class WorkReport extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /**
     * 日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @ExcelField(title = "日期", sort = 2)
    private LocalDate date;

    /**
     * 用户id
     */
    private Integer userId;

    /**
     * 用户名称
     */
    @NoneColumn
    @ExcelField(title = "姓名", sort = 1)
    private String userName;

    /**
     * 项目id
     */
    private Integer projectId;

    /**
     * 项目名称
     */
    @NoneColumn
    @ExcelField(title = "项目", sort = 4)
    private String projectName;

    /**
     * jira号
     */
    @ExcelField(title = "jira", sort = 3)
    private String jira;

    /**
     * parent jira code
     */
    @NoneColumn
    private String parentJira;

    /**
     * 工作时间:分
     */
    @ExcelField(title = "时间(分钟)", sort = 5)
    private Integer duration;

    /**
     * 工作内容(包含完成度)
     */
    @ExcelField(title = "工作内容", sort = 6)
    private String content;

    /**
     * 子jira号
     */
    @ExcelField(title = "subJira", sort = 7)
    private String subJira;


    /**
     * 工作时间 小时
     */
    @NoneColumn
    // 这里指定序列化和反序列化时的格式，比如保留两位小数
//    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "0.00")
    private BigDecimal durationHour;

    /***************** set|get  start **************************************/
    /**
     * set：日期
     */
    public WorkReport setDate(LocalDate date) {
        this.date = date;
        return this;
    }

    /**
     * get：日期
     */
    public LocalDate getDate() {
        return date;
    }

    /**
     * set：用户id
     */
    public WorkReport setUserId(Integer userId) {
        this.userId = userId;
        return this;
    }

    /**
     * get：用户id
     */
    public Integer getUserId() {
        return userId;
    }

    /**
     * set：项目id
     */
    public WorkReport setProjectId(Integer projectId) {
        this.projectId = projectId;
        return this;
    }

    /**
     * get：项目id
     */
    public Integer getProjectId() {
        return projectId;
    }

    /**
     * set：jira号
     */
    public WorkReport setJira(String jira) {
        this.jira = jira;
        return this;
    }

    /**
     * get：jira号
     */
    public String getJira() {
        return jira;
    }

    /**
     * set：工作时间:分
     */
    public WorkReport setDuration(Integer duration) {
        this.duration = duration;
        return this;
    }

    /**
     * get：工作时间:分
     */
    public Integer getDuration() {
        return duration;
    }

    /**
     * set：工作内容(包含完成度)
     */
    public WorkReport setContent(String content) {
        this.content = content;
        return this;
    }

    /**
     * get：工作内容(包含完成度)
     */
    public String getContent() {
        return content;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    public String getParentJira() {
        return parentJira;
    }

    public void setParentJira(String parentJira) {
        this.parentJira = parentJira;
    }

    public String getSubJira() {
        return subJira;
    }

    public void setSubJira(String subJira) {
        this.subJira = subJira;
    }

    public BigDecimal getDurationHour() {
        if (duration != null && durationHour == null) {
            durationHour = ReportCommonHelper.toHoursNumber(duration);
        }
        return durationHour;
    }

    public void setDurationHour(BigDecimal durationHour) {
        if (durationHour != null) {
            duration = ReportCommonHelper.toMinutesNumber(durationHour).intValue();
        }
        this.durationHour = durationHour;
    }

    /**
     * @return 不再限制删除自己的日报：InputtableDateEnum.isLegalDate(this.date);
     */
    public boolean getCouldDelete() {
        return SessionHelper.couldEdit(this.userId);
    }
    /***************** set|get  end **************************************/
}
